# -*- coding: utf-8 -*-
# filename:configs.py
import logging
import os
from pathlib import Path
from datetime import timedelta


class BaseConfig:
    SECRET_KEY = os.getenv('SECRET_KEY', 'dev key')

    # mysql 数据库的配置信息
    SQLALCHEMY_DATABASE_URI = ""

    # redis配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # 默认日志等级
    LOG_LEVEL = logging.DEBUG

    # jwt验证配置
    JWT_TOKEN_LOCATION = ["headers", "cookies"]
    JWT_SECRET_KEY = 'MHP'
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(days=3)

    MAIL_SERVER="smtp.qq.com"
    MAIL_PORT=465
    MAIL_USE_SSL= True
    MAIL_USERNAME="1839335818@qq.com"
    MAIL_PASSWORD="cqxmqeefnntmbjhi"
    MAIL_DEFAULT_SENDER="1839335818@qq.com"

    #
    ROOT_PATH = Path(__file__).parent


class DevelopmentConfig(BaseConfig):
    """开发配置"""
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:123456@127.0.0.1:3306/LiuX"
    SQLALCHEMY_TRACK_MODIFICATIONS = False


class TestingConfig(BaseConfig):
    """测试配置"""
    SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'  # 内存数据库


class ProductionConfig(BaseConfig):
    """生成环境配置"""
    SQLALCHEMY_DATABASE_URI = "mysql://root:root@127.0.0.1:3306/LiuX"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 错误级别记录日志
    LOG_LEVEL = logging.ERROR


config = {
    'dev': DevelopmentConfig,
    'test': TestingConfig,
    'prod': ProductionConfig
}
